package third;

import com.alibaba.fastjson.JSON;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.Map;

/**
 * \* User: MeiZhongHao
 * \* Date: 2019-05-29
 * \* Time: 09:48
 * \* Description:
 * \
 */
public class AbstractBaiduService extends AbstractHttpClient{

    @Override
    public void encrypt(HttpParam param) {
        String signSrc = "datetime=%s&identity=%s&models=%s&name=%s&phone=%s&reqid=%s&service_id=%s&sign_type=%s&sp_no=%s&key=%s";
        String sign = String.format(signSrc, param.getUrlParams().get("datetime"), param.getUrlParams().get("identity"), "general_preA",
                param.getUrlParams().get("name"), param.getUrlParams().get("phone"), param.getUrlParams().get("reqid"), "1007", "1",
                param.getUrlParams().get("sp_no"),
                "18456bdf20d97b4eda53de785ae9c556062a982a");
        try {
            sign = DigestUtils.md5Hex(sign);
            param.getUrlParams().put("sign", sign);
        } catch (Exception e) {
        }
    }

    @Override
    public void call(HttpParam param) {
        try {
            String res = HttpUtil.get(param.getThirdUrl(), param.getUrlParams());
            param.setRespSource(res);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void analyze(HttpParam param) {
        param.setRespData(JSON.parseObject((String) param.getRespSource(),Map.class));
    }


}